//
//  NSObject+DHRuntime.m
//  新浪微博OC
//
//  Created by DIANGHONG on 2018/4/17.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "NSObject+DHRuntime.h"
#import<objc/runtime.h>
@implementation NSObject (DHRuntime)


//获取所有成员变量ivarsList
+ (NSArray *)dh_ivarsList{
    
    //创建可变数组
    NSMutableArray *arrayM = [NSMutableArray array];
    
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([self class], &count);
    
    for (int i = 0; i < count; i++) {
        
        Ivar ivar = ivars[i];
        
        const char *chrName = ivar_getName(ivar);
        
        NSString *name = [NSString stringWithCString:chrName encoding:NSUTF8StringEncoding];
        
        [arrayM addObject:name];
    }
    //释放数组
    free(ivars);
    
    return [arrayM copy];
}

@end
